Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rax-image

Package Overview
Dependencies
Maintainers
9
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rax-image

Image component for Rax.

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
299
decreased by-24.69%
Maintainers
9
Weekly downloads
 
Created
Source

Image

npm

描述

用于展示图片

安装

$ npm install rax-image --save

引用

import Image from 'rax-image';

属性

注: 1、支持列表中的 browser代表 Web weex代表 weex miniApp代表阿里小程序wechatMiniprogram代表微信小程序

属性类型默认值必填描述支持
sourceobject: {uri: string}-true设置图片的 uribrowserweexminiAppwechatMiniprogram
styleobject: { width: number height: number }-true图片样式 width 和 height 为必填属性,否则图片无法正常展示,可以补充其他属性browserweexminiAppwechatMiniprogram
fallbackSourceobject: {uri: string}-false备用图片的 uri(当主图加载失败是加载)browserweex
resizeModestring: 'contain' 'cover' 'stretch'-false决定当组件尺寸和图片尺寸不成比例的时候如何调整图片的大小browserweex
modeString:scaleToFillfalse小程序中的图片模式,可选项更多miniAppwechatMiniprogram
qualitystring: 'original' 'normal' 'low' 'high' 'auto'-false图片质量weex
placeholderstring-false占位图的 URL,在图片下载过程中将展示占位图, 图片下载完成后将显示 source 中指定的图片。weex
onClickfunction-false点击图片时的回调函数miniAppwechatMiniprogram
onLoadfunction-false图片加载成功的回调函数browserweexminiAppwechatMiniprogram
onErrorfunction-false图片加载失败的回调函数browserweexminiAppwechatMiniprogram

onLoad onError 返回

当完成图片加载成功/失败时,将分别触发 onLoad/onError 中的回调函数 function(event) => {}

weex 下(iOS/Android)

成员类型描述
successboolean标记图片是否成功加载,成功为 1/true,失败为 0/false
sizeobject加载的图片大小对象
size.naturalWidthnumber图片宽度,如果图片加载失败则为 0/-1
size.naturalHeightnumber图片高度,如果图片加载失败则为 0/-1

Web 下是 web 原生的 Event 事件

成员类型描述
targetdom图片自身元素
target.naturalWidthnumber图片宽度
target.naturalHeightnumber图片高度

小程序下

成员类型描述
typestring事件类型
detailobject点击位置信息
targetobject点击对象属性信息
currentTargetobject同上

示例

普通示例

import { createElement, render } from 'rax';
import DriverUniversal from 'driver-universal';
import Image from '../src/index';

const App = () => {
  const imageRef = useRef(null);
  return (
    <Image
      ref={imageRef}
      source={{
        uri: 'https://gw.alicdn.com/tfs/TB1bBD0zCzqK1RjSZFpXXakSXXa-68-67.png',
      }}
      style={{
        height: '68rpx',
        width: '67rpx',
      }}
    />
  );
};

render(<App />, document.body, { driver: DriverUniversal });

使用 fallbackSource 和 resizeMode

import { createElement, render } from 'rax';
import DriverUniversal from 'driver-universal';
import Image from '../src/index';

const App = () => {
  return (
    <Image
      source={{
        uri:
          'https://gw.alicdn.com/tfs/TB1g6AvPVXXXXa7XpXXXXXXXXXX-215-215.png',
      }}
      fallbackSource={{
        uri:
          'https://gw.alicdn.com/tps/i3/TB1yeWeIFXXXXX5XFXXuAZJYXXX-210-210.png_70x70.jpg',
      }}
      style={{
        width: '100rpx',
        height: '100rpx',
      }}
      resizeMode="cover"
    />
  );
};

render(<App />, document.body, { driver: DriverUniversal });

Keywords

FAQs

Package last updated on 13 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc